import mongoose, { Schema, Document } from 'mongoose';
import message from "../entities/Message";

// 定义信箱接口
interface IMessageBox extends Document {
    message: message,
    read:Boolean;
}

// 定义信箱模式
const MessageBoxSchema = new Schema<IMessageBox>({
    message: {type:Object,required:true},
    read:{type:Boolean,required:true}
});

// 封装方法，根据 emailOwner 和 userId 返回 MessageBox
function getMessageBoxByOwnerAndId(emailOwner: string, userId: string){
    try {
        const modelName = `MessageBox_${emailOwner}_${userId}`;
        return mongoose.model<IMessageBox>(modelName, MessageBoxSchema);
    } catch (error) {
        return null; // 发生错误时返回 null`
    }
}

export { getMessageBoxByOwnerAndId };
